package demo

import (
	"github.com/astaxie/beego"
	"github.com/sbabiv/xml2map"
	payutils "wxsdk/wxpay/utils/pay"

	//"fmt"
	"strings"
)

func Demo1() {
	notifyData := `<xml><appid><![CDATA[wx204da65aa7d948b0]]></appid>
<attach><![CDATA[MEMBER_CHARGE]]></attach>
<bank_type><![CDATA[ABC_CREDIT]]></bank_type>
<cash_fee><![CDATA[19987]]></cash_fee>
<coupon_count><![CDATA[1]]></coupon_count>
<coupon_fee>13</coupon_fee>
<coupon_fee_0><![CDATA[13]]></coupon_fee_0>
<coupon_id_0><![CDATA[2000000042109958221]]></coupon_id_0>
<fee_type><![CDATA[CNY]]></fee_type>
<is_subscribe><![CDATA[N]]></is_subscribe>
<mch_id><![CDATA[1394024102]]></mch_id>
<nonce_str><![CDATA[1o69puyf10pv2b9s150dyiu26m8uetr9]]></nonce_str>
<openid><![CDATA[oL3Xyt40-W6dELmF5F1zuIp_Dx8k]]></openid>
<out_trade_no><![CDATA[250443532605591552]]></out_trade_no>
<result_code><![CDATA[SUCCESS]]></result_code>
<return_code><![CDATA[SUCCESS]]></return_code>
<sign><![CDATA[09957F132C852906C960071E88200D9A]]></sign>
<sub_appid><![CDATA[wxc4806963e4bbb21f]]></sub_appid>
<sub_is_subscribe><![CDATA[N]]></sub_is_subscribe>
<sub_mch_id><![CDATA[1497014042]]></sub_mch_id>
<sub_openid><![CDATA[ovn_S5NU4_Z52LkcZTVm1o57qzFU]]></sub_openid>
<time_end><![CDATA[20180817214128]]></time_end>
<total_fee>20000</total_fee>
<trade_type><![CDATA[JSAPI]]></trade_type>
<transaction_id><![CDATA[4200000180201808179613697190]]></transaction_id>
</xml> `

	decoder := xml2map.NewDecoder(strings.NewReader(notifyData))
	result, err := decoder.Decode()
	if err != nil {
		beego.Debug("PayNotify:", err.Error())
		return
	}
	rspMap := result["xml"].(map[string]interface{})
	Appkey := "123456789"
	sign := payutils.MakeSign(rspMap, Appkey)
	beego.Debug("sign:", sign)

}
